//package com.neusoft.weekreport.component.bizService.impl;
//
//import com.neusoft.weekreport.component.bizService.ExportWeekToExcelService;
//import com.neusoft.weekreport.component.bizService.SendMailBizService;
//import com.neusoft.weekreport.component.bizService.UserBizService;
//import com.neusoft.weekreport.component.bizService.WeekBizService;
//import com.neusoft.weekreport.component.entities.*;
//import com.neusoft.weekreport.component.req.*;
//import com.neusoft.weekreport.mapper.*;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Configurable;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.CollectionUtils;
//import org.springframework.util.StringUtils;
//
//import javax.activation.DataSource;
//import javax.annotation.Resource;
//import javax.mail.util.ByteArrayDataSource;
//import java.io.ByteArrayOutputStream;
//import java.text.SimpleDateFormat;
//import java.util.*;
//
//@Component
//@Configurable
//@EnableScheduling
//
//public class MailTaskServiceImpl {
//
//    Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Resource
//    SendMailBizService sendMailBizService;
//
//
//    @Resource
//    WeekBizService weekBizService;
//
//    @Value("${spring.mail.receiver}")
//    private String receiver;
//
//    @Value("${spring.mail.contact}")
//    private String contact;
//
//    @Value("${spring.mail.exportreceiver}")
//    private String exportreceiver;
//
//    @Value("${spring.mail.exportcontact}")
//    private String exportcontact;
//
//    @Value("${spring.url.innernet}")
//    private String innernet;
//
//    @Value("${spring.url.outernet}")
//    private String outernet;
//
//    @Value("${spring.leaderid}")
//    private String leaderid;
//
//    private MsGroup msGroupGlobal;
//
//
//    @Resource
//    BsWeekDetailMapper bsWeekDetailMapper;
//    @Resource
//    BsWeekSummaryMapper bsWeekSummaryMapper;
//    @Resource
//    MsUserMapper msUserMapper;
//    @Resource
//    DcProjectMapper dcProjectMapper;
//    @Resource
//    DcProductMapper dcProductMapper;
//
//    @Resource
//    MsGroupRefUserMapper msGroupRefUserMapper;
//    @Resource
//    BgUserRefRoleMapper bgUserRefRoleMapper;
//    @Resource
//    MsGroupMapper msGroupMapper;
//    @Resource
//    TimeTaskMapper timeTaskMapper;
//
//    @Resource
//    ExportWeekToExcelService exportWeekToExcelService;
//    @Resource
//    UserBizService userBizService;
//
//    @Resource
//    DcWeekMapper dcWeekMapper;
//
//    @Resource
//    ReWeekSummaryMapper reWeekSummaryMapper;
//
//    //每周五早上9点发送邮件
//    @Scheduled(cron = "${spring.time1}")
//    public void fridaySendMail() throws Exception {
//        SendMailInfo sendMailInfo = new SendMailInfo();
//        String html ="<p>各位老师好：</p>\n" +
//                "<p style='text-indent:2em;'>请于今天填写本周周报，周报系统详细地址如下：</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'>内网地址：" +innernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold'> 外网地址："+ outernet +"</p>\n" +
//                "<p style='text-indent:2em;font-weight: bold;color:#4797ff;'>注：此邮件为自动发送，请勿回复，如果有疑问，请及时联系王丹，谢谢！</p> ";
//        sendMailInfo.setMailContent(html);
//        sendMailInfo.setSendtitle("关于本周周报");
//        sendMailInfo.setContact(contact);
//        sendMailInfo.setReceiver(receiver);
//        sendMailBizService.sendMail(sendMailInfo);
//        logger.info("每周五定时发送周报通知邮件");
//    }
//
//    //每周五下午四点半发送邮件
//    @Scheduled(cron = "${spring.time2}")
//    public void weekNoSubmitNotify() throws Exception {
//        SendMailInfo sendMailInfo = new SendMailInfo();
//        NowWeekInfo nowWeekInfo = getNowWeekInfo();
//        String weekId = nowWeekInfo.getWeekId();
//
//        List<String> groupIdList = getGroupIdList();
//        if(CollectionUtils.isEmpty(groupIdList)){
//            return;
//        }
//        List<String> userIdList = getUserIdList(groupIdList);
//        if(CollectionUtils.isEmpty(userIdList)){
//            return;
//        }
//        //本周周报明细未提交信息
//        List<String> taskTypeList = new ArrayList<>();
//        taskTypeList.add("1");
//        taskTypeList.add("2");
//        List<weekDetailNoSummit> noSubmitWeek = getNoSubmitWeek(groupIdList,userIdList,weekId,taskTypeList);
//
//        //下周计划未提交信息
//        List<String> taskTypeList1 = new ArrayList<>();
//        taskTypeList1.add("3");
//        taskTypeList1.add("4");
//        List<weekDetailNoSummit> noSubmitNextWeek = getNoSubmitWeek(groupIdList,userIdList,weekId,taskTypeList1);
//
//        //周报概述未提交信息
//        List<ProjectWeekSummaryNoSubmit> summaryTaskList = getNoSubmitWeekSummary(groupIdList,userIdList,weekId);
//        if(noSubmitWeek.size()==0 && noSubmitNextWeek.size()==0 && summaryTaskList.size()==0){
//            return;
//        }
//        String html ="      <!DOCTYPE html>\n" +
//                "                  <head lang=\"en\">\n" +
//                "                   <meta charset=\"UTF-8\">\n" +
//                "                   </head>\n" +
//                "          <style type=\"text/css\">\n" +
//                "            .th {\n" +
//                "                padding: 0;\n" +
//                "                margin: 0;\n" +
//                "                vertical-align: bottom;\n" +
//                "                border-bottom: 1px solid #ddd;\n" +
//                "            }\n" +
//                "          </style>\n" +
//                "                <body>\n" +
//                "                <p>各位老师好：</p>\n" +
//                "                <p style=\"text-indent:2em;\">今天到目前时间点为止，周报明细填写情况如下,请未填写的尽快填写：</p>\n" +
//                "\n" +
//                "                <div style=\"width: 100%;margin:auto\">\n" +
//                "                    <table border=\"1\" style=\"width: 80%;text-align: center;font-size: 14px\">\n" +
//                "                        <tr style=\"background-color: #8bc0ad;color: #FFFFFF\">\n" +
//                "                            <th rowspan=\"2\" style=\"width: 10%\">\n" +
//                "                                组\n" +
//                "                            </th>\n" +
//                "                            <th colspan=\"3\" style=\"width: 90%\">\n" +
//                "                                本周工作明细\n" +
//                "                            </th>\n" +
//                "                        </tr>\n" +
//                "                        <tr style=\"background-color: #8bc0ad;color: #FFFFFF\">\n" +
//                "                            <th style=\"width: 10%\">\n" +
//                "                                已提交(人)\n" +
//                "                            </th>\n" +
//                "                            <th style=\"width: 10%\">\n" +
//                "                                未提交(人)\n" +
//                "                            </th>\n" +
//                "                             <th style=\"width: 70%\">\n" +
//                "                                具体未提交组员姓名\n" +
//                "                            </th>\n" +
//                "                        </tr>";
//        for (weekDetailNoSummit noSummit : noSubmitWeek) {
//            if(StringUtils.isEmpty(noSummit.getNoSubmitPerson())){
//                html +="   <tr>\n" +
//                        "                            <th style=\"width: 10%\">\n" +
//                        "                                "+noSummit.getGroupName()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:blue\">\n" +
//                        "                                "+noSummit.getSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:red\">\n" +
//                        "                                "+noSummit.getNoSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 70%;font-weight:normal;color:blue\">\n" +
//                        "                                全部提交\n" +
//                        "                            </th>\n" +
//                        "                        </tr>";
//            }else{
//                html +="   <tr>\n" +
//                        "                            <th style=\"width: 10%\">\n" +
//                        "                                "+noSummit.getGroupName()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:blue\">\n" +
//                        "                                "+noSummit.getSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:red\">\n" +
//                        "                                "+noSummit.getNoSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 70%;font-weight:normal;color:red\">\n" +
//                        "                                "+noSummit.getNoSubmitPerson()+"\n" +
//                        "                            </th>\n" +
//                        "                        </tr>";
//            }
//
//        }
//        html +=" </table>\n" +
//                "                </div>\n" +
//                "                <br>\n" +
//                "                <p style=\"text-indent:2em;\">下周计划填写情况如下：</p>\n"+
//                "                   <div style=\"width: 100%;margin:auto\">\n" +
//                "                    <table border=\"1\" style=\"width: 80%;text-align: center;font-size: 14px\">\n" +
//                "                        <tr style=\"background-color: #8bc0ad;color: #FFFFFF\">\n" +
//                "                            <th rowspan=\"2\" style=\"width: 10%\">\n" +
//                "                                组\n" +
//                "                            </th>\n" +
//                "                            <th colspan=\"3\" style=\"width: 90%\">\n" +
//                "                                下周计划明细\n" +
//                "                            </th>\n" +
//                "                        </tr>\n" +
//                "                        <tr style=\"background-color: #8bc0ad;color: #FFFFFF\">\n" +
//                "                            <th style=\"width: 10%\">\n" +
//                "                                已提交(人)\n" +
//                "                            </th>\n" +
//                "                            <th style=\"width: 10%\">\n" +
//                "                                未提交(人)\n" +
//                "                            </th>\n" +
//                "                             <th style=\"width: 70%\">\n" +
//                "                                具体未提交组员姓名\n" +
//                "                            </th>\n" +
//                "                        </tr>";
//        for (weekDetailNoSummit noNextSummit : noSubmitNextWeek) {
//            if(StringUtils.isEmpty(noNextSummit.getNoSubmitPerson())){//全部提交
//                html +="   <tr>\n" +
//                        "                            <th style=\"width: 10%\">\n" +
//                        "                                "+noNextSummit.getGroupName()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:blue\">\n" +
//                        "                                "+noNextSummit.getSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:red;\">\n" +
//                        "                                "+noNextSummit.getNoSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 70%;font-weight:normal;color:blue\">\n" +
//                        "                                全部提交\n" +
//                        "                            </th>\n" +
//                        "                        </tr>";
//            }else{
//                html +="   <tr>\n" +
//                        "                            <th style=\"width: 10%\">\n" +
//                        "                                "+noNextSummit.getGroupName()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:blue\">\n" +
//                        "                                "+noNextSummit.getSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 10%;font-weight:normal;color:red;\">\n" +
//                        "                                "+noNextSummit.getNoSubmitCount()+"\n" +
//                        "                            </th>\n" +
//                        "                            <th style=\"width: 70%;font-weight:normal;color:red;\">\n" +
//                        "                                "+noNextSummit.getNoSubmitPerson()+"\n" +
//                        "                            </th>\n" +
//                        "                        </tr>";
//            }
//
//        }
//
//        html +=" </table>\n" +
//                "                </div>\n" +
//                "                <br>\n" +
//                "                <p style=\"text-indent:2em;\">周报项目概述填写情况如下：</p>\n" +
//                "                <div style=\"width: 100%;margin:auto\">\n" +
//                "                    <table border=\"1\" style=\"width: 80%;text-align: center;font-size: 14px\">\n" +
//                "                        <tr style=\"background-color: #8bc0ad;color: #FFFFFF\">\n" +
//                "                            <th rowspan=\"2\" style=\"width: 10%\">\n" +
//                "                                组\n" +
//                "                            </th>\n" +
//                "                            <th colspan=\"2\" style=\"width: 90%\">\n" +
//                "                                本周工作项目概述\n" +
//                "                            </th>\n" +
//                "                        </tr>\n" +
//                "                        <tr style=\"background-color: #8bc0ad;color: #FFFFFF\">\n" +
//                "                            <th style=\"width: 90%\">\n" +
//                "                                未提交的项目支持\n" +
//                "                            </th>\n" +
//                "                        </tr>";
//        for (ProjectWeekSummaryNoSubmit summaryNoSubmit : summaryTaskList) {
//            html +="   <tr>\n" +
//                    "                            <th style=\"width: 10%\">\n" +
//                    "                                "+summaryNoSubmit.getGroupName()+"\n" +
//                    "                            </th>\n";
//
//            if(summaryNoSubmit.getNoSubmitProjectInfo().equals("2")){//全部提交
//                html += "                            <th align=\"left\" style=\"width: 90%;align:left;font-weight:normal;color:blue\">\n" +
//                        "                                全部提交\n" +
//                        "                            </th>\n" +
//                        "                        </tr>";
//            }else if(summaryNoSubmit.getNoSubmitProjectInfo().equals("1")){
//                html += "                            <th align=\"left\" style=\"width: 90%;font-weight:normal;color:red\">\n" +
//                        "                                周报明细未提交，无概述\n" +
//                        "                            </th>\n";
//            }
//            else{
//                html += "                            <th align=\"left\" style=\"width: 90%;align:left;font-weight:normal\">\n" +
//                        "                                "+summaryNoSubmit.getNoSubmitProjectInfo()+"\n" +
//                        "                            </th>\n" +
//                        "                        </tr>";
//            }
//        }
//
//        html +="</table>\n" +
//                "                </div>\n" +
//                "                <br>\n" +
//                "               <p style=\"text-indent:2em;font-weight: bold;color:#4797ff;\">注：此邮件为自动发送，请勿回复，如果有疑问，请及时联系王丹，谢谢！</p>\n" +
//                "               </body>\n" +
//                "               </html>\n";
//        sendMailInfo.setMailContent(html);
//        sendMailInfo.setSendtitle("通告：周报填写进展");
//        sendMailInfo.setContact(contact);
//        sendMailInfo.setReceiver(receiver);
//        sendMailBizService.sendMail(sendMailInfo);
//        logger.info("通告周报填写进展");
//    }
//
//    //每周五下午四点半发送研发概述未填写的邮件
//    @Scheduled(cron = "${spring.time2}")
//    public void productSummaryNoSubmitNotify() throws Exception {
//        SendMailInfo sendMailInfo = new SendMailInfo();
//        NowWeekInfo nowWeekInfo = getNowWeekInfo();
//        String weekId = nowWeekInfo.getWeekId();
//
//        //周报概述未提交信息
//        List<ReWeekSummary> reWeekSummaryList= getNoSubmitProductSummaryInfo(weekId);
//
//        if(reWeekSummaryList.size()==0){
//            return;
//        }
//        String userName="";
//        String html ="      <!DOCTYPE html>\n" +
//                "                  <head lang=\"en\">\n" +
//                "                   <meta charset=\"UTF-8\">\n" +
//                "                   </head>\n" +
//                "          <style type=\"text/css\">\n" +
//                "            .th {\n" +
//                "                padding: 0;\n" +
//                "                margin: 0;\n" +
//                "                vertical-align: bottom;\n" +
//                "                border-bottom: 1px solid #ddd;\n" +
//                "            }\n" +
//                "          </style>\n" +
//                "                <body>\n" +
//                "                <p>各位老师好：</p>\n" +
//                "                <p style=\"text-indent:2em;\">因周报的研发概述，之前是各组负责人编写本组对应的研发概述，现在改为产品负责人填写，请各位老师尽快填写本周未填写的研发概述：</p>\n" +
//                "                " +
//                "                <div style=\"width: 100%;margin:auto\">\n" +
//                "                    <table border=\"1\" style=\"width: 50%;text-align: center;font-size: 14px\">\n" +
//                "                        <tr style=\"background-color: #8bc0ad;color: #FFFFFF\">\n" +
//                "                            <th  style=\"width: 10%\">\n" +
//                "                                负责人\n" +
//                "                            </th>\n" +
//                "                            <th  style=\"width: 90%\">\n" +
//                "                                本周工作未提交研发的概述\n" +
//                "                            </th>\n" +
//                "                        </tr>\n";
//        for (ReWeekSummary reWeekSummary : reWeekSummaryList) {
//            html +="   <tr>\n" +
//                    "                            <th style=\"width: 10%\">\n" +
//                    "                                "+reWeekSummary.getUserName()+"老师"+"\n" +
//                    "                            </th>\n";
//
//            html += "                            <th align=\"left\" style=\"width: 90%;align:left;font-weight:normal;color:red\">\n" +
//                        "                                "+reWeekSummary.getTaskName()+"\n" +
//                        "                            </th>\n" +
//                        "                        </tr>";
//            userName += reWeekSummary.getAccountName()+"@neusoft.com,";
//
//        }
//
//        html +="</table>\n" +
//                "                </div>\n" +
//                "                <br>\n" +
//                "               <p style=\"text-indent:2em;font-weight: bold;color:#4797ff;\">注：此邮件为自动发送，请勿回复，如果有疑问，请及时联系王丹，谢谢！</p>\n" +
//                "               </body>\n" +
//                "               </html>\n";
//        sendMailInfo.setMailContent(html);
//        sendMailInfo.setSendtitle("通告：周报研发概述填写进展");
//        sendMailInfo.setContact(exportcontact);
//        sendMailInfo.setReceiver(userName);
//        sendMailBizService.sendMail(sendMailInfo);
//        logger.info("周报研发概述填写进展");
//    }
//
//    //周报明细未填写人<=3人，周报概述全部提交时，将周报导出发送给领导
//    @Scheduled(cron = "${spring.time3}")
//    @Transactional
//    public void exportWeekIfAllSubmit() throws Exception{
//        NowWeekInfo nowWeekInfo = getNowWeekInfo();
//        TimeTaskExample timeTaskExample = new TimeTaskExample();
//        TimeTaskExample.Criteria criteria = timeTaskExample.createCriteria();
//        criteria.andWeekidEqualTo(nowWeekInfo.getWeekId());
//        List<TimeTask> timeTasksList = timeTaskMapper.selectByExample(timeTaskExample);
//        if(CollectionUtils.isEmpty(timeTasksList)){
//
//            List<String> groupIdList = getGroupIdList();
//            if(CollectionUtils.isEmpty(groupIdList)){
//                return;
//            }
//            List<String> userIdList = getUserIdList(groupIdList);
//            if(CollectionUtils.isEmpty(userIdList)){
//                return;
//            }
//            //本周周报明细未提交信息
//            List<String> taskTypeList = new ArrayList<>();
//            taskTypeList.add("1");
//            taskTypeList.add("2");
//            List<weekDetailNoSummit> noSubmitWeek = getNoSubmitWeek(groupIdList,userIdList,nowWeekInfo.getWeekId(),taskTypeList);
//            int count1=0;
//            for (weekDetailNoSummit weekDetailNoSummit : noSubmitWeek) {
//                count1 +=Integer.parseInt(weekDetailNoSummit.getNoSubmitCount());
//            }
//            //下周计划未提交信息
//            List<String> taskTypeList1 = new ArrayList<>();
//            taskTypeList1.add("3");
//            taskTypeList1.add("4");
//            List<weekDetailNoSummit> noSubmitNextWeek = getNoSubmitWeek(groupIdList,userIdList,nowWeekInfo.getWeekId(),taskTypeList1);
//            int count2=0;
//            for (weekDetailNoSummit weekDetailNoSummit : noSubmitNextWeek) {
//                count2 +=Integer.parseInt(weekDetailNoSummit.getNoSubmitCount());
//            }
//
//            //周报概述未提交信息
//            List<ProjectWeekSummaryNoSubmit> summaryTaskList = getNoSubmitWeekSummary(groupIdList,userIdList,nowWeekInfo.getWeekId());
//            for (ProjectWeekSummaryNoSubmit weekSummaryNoSubmit : summaryTaskList) {
//                String projectResult = weekSummaryNoSubmit.getNoSubmitProjectInfo();
////                String productResult = weekSummaryNoSubmit.getNoSubmitProductInfo();
//                if(projectResult.equals("2") || projectResult.equals("1")){
//                    continue;
//                }else{
//                    return;
//                }
//            }
//
//            List<ReWeekSummary> noSummitProductList = getNoSubmitProductSummaryInfo(nowWeekInfo.getWeekId());
//            int count3 = noSummitProductList.size();
//
//            if(count1<=3 && count2<=3 && count3<=2){
//
//                logger.info("*************************已经符合条件，开始进行导出************************");
//                ExportWeekInfoReq req = new ExportWeekInfoReq();
////                MsGroupExample msGroupExample = new MsGroupExample();
////                MsGroupExample.Criteria criteria1 = msGroupExample.createCriteria();
////                criteria1.andIdIn(groupIdList);
////                List<MsGroup> msGroupList = msGroupMapper.selectByExample(msGroupExample);
//
//                req.setWeekId(nowWeekInfo.getWeekId());
//                req.setUserIdList(userIdList);
//                List<MsGroup> msGroupList = new ArrayList<>();
//                msGroupList.add(msGroupGlobal);
//                req.setGroupIdList(msGroupList);
//                req.setWeek(nowWeekInfo.getWeek());
//                String department = userBizService.recuisiveQuery(groupIdList.get(0));
//                req.setDepartment(department);
//                req.setStartDate(nowWeekInfo.getStartDate());
//                req.setEndDate(nowWeekInfo.getEndDate());
//                req.setUserId(leaderid);
//                XSSFWorkbook workbook = exportWeekToExcelService.writeExcelInfo(req);
//                String fileName = "云医疗事业部-" + department.replace("开发部","") + "产品线-研发周报("+ nowWeekInfo.getWeek()+").xlsx";//文件名称
//
//                //以流文件发送附件
//                ByteArrayOutputStream bos = new ByteArrayOutputStream();
//                workbook.write(bos);//把excel写入到字节数组中
//                bos.close();
//                DataSource dataSource = new ByteArrayDataSource(bos.toByteArray(),"application/vnd.ms-excel");
//
//                SendMailInfo sendMailInfo = new SendMailInfo();
//                String html="<p>领导好：</p>\n" +
//                        "<p style='text-indent:2em;'>本周周报各位负责人已填写完成，并导出到excel，如附件：</p>\n" +
//                        "<p style='text-indent:2em;'>如需修改周报，或者查看详细信息，请登录如下周报系统地址：</p>\n" +
//                        "<p style='text-indent:2em;font-weight: bold'>内网地址：" +innernet +"</p>\n" +
//                        "<p style='text-indent:2em;font-weight: bold'> 外网地址："+ outernet +"</p>\n" +
//                        "<p style='text-indent:2em;font-weight: bold;color:#4797ff;'>注：此邮件为自动发送，请勿回复，如果有疑问，请及时联系王丹，谢谢！</p> ";;
//                sendMailInfo.setMailContent(html);
//                sendMailInfo.setSendtitle("已导出：本周周报");
//                sendMailInfo.setContact(exportcontact);
//                sendMailInfo.setReceiver(exportreceiver);
//                sendMailInfo.setAttachName(fileName);
//                sendMailInfo.setAttachFile(dataSource);
//                Boolean flag = true;
//                try{
//                    sendMailBizService.sendMail(sendMailInfo);
//                }catch (Exception e){
//                    flag = false;
//                    logger.error("发送周报导出邮件失败");
//                    logger.error(e.toString());
//                }
//                if(flag){
//                    logger.info("本周周报已导出");
//                    TimeTask timeTask = new TimeTask();
//                    timeTask.setId(UUID.randomUUID().toString());
//                    timeTask.setUseFlag("1");
//                    timeTask.setWeekid(nowWeekInfo.getWeekId());
//                    timeTaskMapper.insert(timeTask);
//                }
//
//            }else{
//                logger.info("*************************还不符合导出条件，定时任务继续执行************************");
//                return;
//            }
//
//        }else{
//            logger.info("*************************本周已经导出过一次，不再导出************************");
//        }
//    }
//
//    public List<String> getGroupIdList(){
//
//        logger.info("**********************开始:查询组id**************************");
//
//        MsGroupRefUserExample msGroupRefUserExample = new MsGroupRefUserExample();
//        MsGroupRefUserExample.Criteria criteria = msGroupRefUserExample.createCriteria();
//        criteria.andUseridEqualTo(leaderid);
//        List<MsGroupRefUser>  msGroupRefUserList = msGroupRefUserMapper.selectByExample(msGroupRefUserExample);
//        HashSet groupIdSet = new HashSet();
//        for (MsGroupRefUser msGroupRefUser : msGroupRefUserList) {
//            MsGroup msGroup = msGroupMapper.selectByPrimaryKey(msGroupRefUser.getGroupid());
//            msGroupGlobal = msGroup;
//            if(!msGroup.getParentId().equals("-1")){
//                groupIdSet.add(msGroupRefUser.getGroupid());
//            }
//            List<String> GroupIdList = new ArrayList<>();
//            GroupIdList = getALlGroup(GroupIdList,msGroupRefUser.getGroupid());
//            for (String groupId : GroupIdList) {
//                groupIdSet.add(groupId);
//            }
//        }
//        List<String> groupIdList = new ArrayList<>(groupIdSet);//查询出此领导下所有组id
//        logger.info("**********************结束:查询组id**************************");
//        return groupIdList;
//    }
//        //递归查询所有组
//    public List<String> getALlGroup(List<String> GroupIdList,String groupId){
//
//        MsGroupExample msGroupExample = new MsGroupExample();
//        MsGroupExample.Criteria criteria3 = msGroupExample.createCriteria();
//        criteria3.andParentIdEqualTo(groupId);
//        criteria3.andEnableEqualTo(1);
//        criteria3.andWeekFlagEqualTo(1);
//        List<MsGroup> msGroupList = msGroupMapper.selectByExample(msGroupExample);
//        if(!CollectionUtils.isEmpty(msGroupList)){
//            for (MsGroup msGroup : msGroupList) {
//                GroupIdList.add(msGroup.getId());
//                getALlGroup(GroupIdList,msGroup.getId());
//            }
//        }else{
//            GroupIdList.add(groupId);
//        }
//        return GroupIdList;
//    }
//    public List<String> getUserIdList(List<String> groupIdList){
//        logger.info("**********************开始:查询用户id**************************");
//        MsGroupRefUserExample msGroupRefUserExample = new MsGroupRefUserExample();
//        MsGroupRefUserExample.Criteria criteria1 = msGroupRefUserExample.createCriteria();
//        criteria1.andGroupidIn(groupIdList);
//        List<MsGroupRefUser> msGroupRefUserList1 = msGroupRefUserMapper.selectByExample(msGroupRefUserExample);
//
//        //查询出管理员和领导角色的用户
//        BgUserRefRoleExample bgUserRefRoleExample = new BgUserRefRoleExample();
//        BgUserRefRoleExample.Criteria criteria3 = bgUserRefRoleExample.createCriteria();
//        List<String> roleIdList = new ArrayList<>();
//        roleIdList.add("10004");
//        roleIdList.add("10001");
//        criteria3.andRoleIdIn(roleIdList);
//        List<BgUserRefRole> bgUserRefRoleList = bgUserRefRoleMapper.selectByExample(bgUserRefRoleExample);
//        List<String> leadUserIdList = new ArrayList<>();
//        for (BgUserRefRole bgUserRefRole : bgUserRefRoleList){
//            leadUserIdList.add(bgUserRefRole.getUserId());
//        }
//        HashSet userIdSet = new HashSet();
//        for (MsGroupRefUser msGroupRefUser : msGroupRefUserList1) {
//            if(!leadUserIdList.contains(msGroupRefUser.getUserid())){
//                userIdSet.add(msGroupRefUser.getUserid());
//            }
//        }
//        List<String> userIdList = new ArrayList<>(userIdSet);//查询出此领导下所有组员(包含禁用)
//        MsUserExample msUserExample = new MsUserExample();
//        MsUserExample.Criteria criteria = msUserExample.createCriteria();
//        criteria.andIdIn(userIdList);
//        criteria.andEnableEqualTo(1);
//        List<MsUser> msUserList = msUserMapper.selectByExample(msUserExample);
//        List<String> newUserIdList = new ArrayList<>();
//        for (MsUser msUser : msUserList) {
//            newUserIdList.add(msUser.getId());
//        }
//        logger.info("**********************结束:查询用户id**************************");
//        return  newUserIdList;
//    }
//
//    public List<weekDetailNoSummit> getNoSubmitWeek(List<String> groupIdList,List<String> userIdList, String weekId,List<String> taskTypeList){
//
//        logger.info("**********************开始:查询周报明细**************************");
//        //查询周报明细,得到未提交的账号
//        BsWeekDetailExample bsWeekDetailExample = new BsWeekDetailExample();
//        BsWeekDetailExample.Criteria criteria2 = bsWeekDetailExample.createCriteria();
//        criteria2.andMainPersonIdIn(userIdList);
//        criteria2.andWeekidEqualTo(weekId);
//        criteria2.andTaskTypeIn(taskTypeList);
//        List<BsWeekDetail> bsWeekDetailList = bsWeekDetailMapper.selectByExample(bsWeekDetailExample);
//
//        List<String> submitUserIdList = new ArrayList<>();
//        if(CollectionUtils.isEmpty(bsWeekDetailList)){//没有人填写周报
//
//        }else{
//            HashSet submitUserId = new HashSet();
//            for (BsWeekDetail bsWeekDetail : bsWeekDetailList) {
//                submitUserId.add(bsWeekDetail.getMainPersonId());
//            }
//            submitUserIdList = new ArrayList<>(submitUserId);
//        }
//
//        List<String> noSubmitUserIdList = new ArrayList<>();
//        for (String userId : userIdList) {
//            if(submitUserIdList.contains(userId)){
//                continue;
//            }else{
//                noSubmitUserIdList.add(userId);//未提交周报的所有账号
//            }
//        }
//        List list = new ArrayList();//存放整理好的周报提交信息
//        for (String groupId : groupIdList) {
//
//                //查询出组下的用户
//                List<String> groupUserIdList = new ArrayList<>();
//                MsGroupRefUserExample msGroupRefUserExample = new MsGroupRefUserExample();
//                MsGroupRefUserExample.Criteria criteria3 = msGroupRefUserExample.createCriteria();
//                criteria3.andGroupidEqualTo(groupId);
//                List<MsGroupRefUser> msGroupRefUserList2 = msGroupRefUserMapper.selectByExample(msGroupRefUserExample);
//                if(!CollectionUtils.isEmpty(msGroupRefUserList2)){
//                    for (MsGroupRefUser msGroupRefUser : msGroupRefUserList2) {
//                        groupUserIdList.add(msGroupRefUser.getUserid());
//                    }
//                }
//
//                //查询出role是1004 领导的用户
//                List<String> leaderUserIdList = new ArrayList<>();
//                HashSet leaderSet  = new HashSet();
//                BgUserRefRoleExample bgUserRefRoleExample = new BgUserRefRoleExample();
//                BgUserRefRoleExample.Criteria criteria4 = bgUserRefRoleExample.createCriteria();
//                criteria4.andRoleIdEqualTo("10004");
//                List<BgUserRefRole> bgUserRefRoleList = bgUserRefRoleMapper.selectByExample(bgUserRefRoleExample);
//                if(!CollectionUtils.isEmpty(bgUserRefRoleList)){
//                    for (BgUserRefRole bgUserRefRole : bgUserRefRoleList) {
//                        leaderSet.add(bgUserRefRole.getUserId());
//                    }
//                    leaderUserIdList = new ArrayList<>(leaderSet);
//                    groupUserIdList.removeAll(leaderUserIdList);
//                }
//
//                //判断组中是否有未提交周报的账号
//                List<String> groupNoSubmitUserIdList = new ArrayList<>();
//                for (String userId : groupUserIdList) {
//                    if (noSubmitUserIdList.contains(userId)) {
//                        groupNoSubmitUserIdList.add(userId);
//                    }
//                }
//                //未提交周报账号
//                String noSubmitPerson = "";
//                if (!CollectionUtils.isEmpty(groupNoSubmitUserIdList)) {
//                    for (String userId : groupNoSubmitUserIdList) {
//                        MsUser msUser = msUserMapper.selectByPrimaryKey(userId);
//                        if (StringUtils.isEmpty(noSubmitPerson)) {
//                            noSubmitPerson = msUser.getUserName();
//                        } else {
//                            noSubmitPerson += ";" + msUser.getUserName();
//                        }
//                    }
//                }
//                int submitCount = groupUserIdList.size() - groupNoSubmitUserIdList.size();
//                weekDetailNoSummit wdns = new weekDetailNoSummit();
//                MsGroup msGroup = msGroupMapper.selectByPrimaryKey(groupId);
//                wdns.setGroupId(groupId);
//                wdns.setGroupName(msGroup.getGroupName());
//                wdns.setSubmitCount(Integer.toString(submitCount));
//                wdns.setNoSubmitCount(Integer.toString(groupNoSubmitUserIdList.size()));
//                wdns.setNoSubmitPerson(noSubmitPerson);
//                list.add(wdns);
//            }
//        logger.info("**********************结束:查询周报明细**************************");
//
//        return list;
//    }
//    public List<ProjectWeekSummaryNoSubmit> getNoSubmitWeekSummary(List<String> groupIdList,List<String> userIdList,String weekId){
//
//        logger.info("**********************开始:查询周报概述**************************");
//        List<ProjectWeekSummaryNoSubmit> list = new ArrayList<>();
//        for (String groupId : groupIdList) {
//            MsGroupRefUserExample msGroupRefUserExample = new MsGroupRefUserExample();
//            MsGroupRefUserExample.Criteria criteria = msGroupRefUserExample.createCriteria();
//            criteria.andGroupidEqualTo(groupId);
//            List<MsGroupRefUser> msGroupRefUserList = msGroupRefUserMapper.selectByExample(msGroupRefUserExample);
//            List<String> userIdAfterGroup = new ArrayList<>();//组下的用户
//            for (MsGroupRefUser msGroupRefUser : msGroupRefUserList) {
//                userIdAfterGroup.add(msGroupRefUser.getUserid());
//            }
//            MsGroup msGroup = msGroupMapper.selectByPrimaryKey(groupId);
//            ProjectWeekSummaryNoSubmit ws = new ProjectWeekSummaryNoSubmit();
//            ws.setGroupId(groupId);
//            ws.setGroupName(msGroup.getGroupName());
//            ws.setUserIdList(userIdAfterGroup);
//            //获取产品概述
////            String noSubmitProductInfo = getNoSubmitProductSummaryInfo(weekId,"2");
//            //获取项目概述
//            String noSubmitProjectInfo = getNoSubmitProjectSummaryInfo(userIdAfterGroup,weekId,groupId,"2");
//
////            ws.setNoSubmitProductInfo(noSubmitProductInfo);
//            ws.setNoSubmitProjectInfo(noSubmitProjectInfo);
//            list.add(ws);
//        }
//        logger.info("**********************结束:查询周报概述**************************");
//        return list;
//
//    }
//    public List<ReWeekSummary> getNoSubmitProductSummaryInfo(String weekId){
//        List<ReWeekSummary> reWeekSummaryList = reWeekSummaryMapper.selectProductNoSummitWeekSummary(weekId);
//
//        return reWeekSummaryList;
//    }
//    public String getNoSubmitProjectSummaryInfo(List<String> userIdAfterGroup,String weekId,String groupId,String taskType){
//
//        BsWeekDetailExample bsWeekDetailExample = new BsWeekDetailExample();
//        BsWeekDetailExample.Criteria criteria1 = bsWeekDetailExample.createCriteria();
//        criteria1.andWeekidEqualTo(weekId);
//        criteria1.andMainPersonIdIn(userIdAfterGroup);
//        criteria1.andTaskTypeEqualTo(taskType);
//        List<BsWeekDetail> bsWeekDetailList = bsWeekDetailMapper.selectByExample(bsWeekDetailExample);
//        String noSubmitSummary = "";
//        if(CollectionUtils.isEmpty(bsWeekDetailList)){
//            noSubmitSummary = "1";//周报明细未提交，无概述
//        }else{
//            HashSet<String> hashSet = new HashSet<>();
//            for (BsWeekDetail bsWeekDetail : bsWeekDetailList) {
//                hashSet.add(bsWeekDetail.getTaskId());
//            }
//            List<String> taskIdList = new ArrayList<>(hashSet);//得到任务I
//            BsWeekSummaryExample bsWeekSummaryExample = new BsWeekSummaryExample();
//            BsWeekSummaryExample.Criteria criteria2 = bsWeekSummaryExample.createCriteria();
//            criteria2.andWeekidEqualTo(weekId);
//            criteria2.andTaskTypeEqualTo(taskType);
//            criteria2.andGroupIdEqualTo(groupId);
//            criteria2.andTaskIdIn(taskIdList);
//            List<BsWeekSummary> bsWeekSummaryList = bsWeekSummaryMapper.selectByExample(bsWeekSummaryExample);
//            List<String> submitTaskId = new ArrayList<>();//提交的周报概述任务Id
//            if(!CollectionUtils.isEmpty(bsWeekSummaryList)){
//                for (BsWeekSummary bsWeekSummary : bsWeekSummaryList) {
//                    if (!StringUtils.isEmpty(bsWeekSummary.getWorkContent())) {
//                        submitTaskId.add(bsWeekSummary.getTaskId());
//                    }
//
//                }
//            }
//            taskIdList.removeAll(submitTaskId);
//            if(!CollectionUtils.isEmpty(taskIdList)){
//                if(taskType.equals("1")){//研发任务概述
//                    for (String taskId : taskIdList) {
//                        DcProduct dcProduct = dcProductMapper.selectByPrimaryKey(taskId);
//                        if(StringUtils.isEmpty(noSubmitSummary)){
//                            noSubmitSummary +=dcProduct.getProductName();
//                        }else{
//                            noSubmitSummary += "；" + dcProduct.getProductName();
//                        }
//                    }
//                }else{
//                    for (String taskId : taskIdList) {
//                        DcProject dcProject = dcProjectMapper.selectByPrimaryKey(taskId);
//                        if(StringUtils.isEmpty(noSubmitSummary)){
//                            noSubmitSummary +=dcProject.getProjectName();
//                        }else{
//                            noSubmitSummary += "；" + dcProject.getProjectName();
//                        }
//                    }
//                }
//            }else{
//                noSubmitSummary="2";//全部提交
//            }
//
//        }
//        return noSubmitSummary;
//    }
//    public NowWeekInfo getNowWeekInfo(){
//        logger.info("**********************开始:获取当前周信息**************************");
//        NowWeekInfo nowWeekInfo = new NowWeekInfo();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        Calendar cal = Calendar.getInstance();
//        cal.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
//        int week = cal.get(Calendar.WEEK_OF_YEAR);
//        int year = cal.get(Calendar.YEAR);
//        int month = cal.get(Calendar.MONTH) + 1;
//        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
//        if(dayWeek==1){
//            dayWeek = 8;
//        }
//        System.out.println("要计算日期为:" + sdf.format(cal.getTime())); // 输出要计算日期
//
//        //所在周星期一的日期
//        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - dayWeek);// 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
//        Date mondayDate = cal.getTime();
//        String weekBegin = sdf.format(mondayDate);
//
//        //所在周星期日的日期
//        cal.add(Calendar.DATE, 4 +cal.getFirstDayOfWeek());
//        Date sundayDate = cal.getTime();
//        String weekEnd = sdf.format(sundayDate);
//
//        nowWeekInfo.setWeekId(weekBegin + "-" + weekEnd);
//
//        //年周转换为月周
//        DcWeekExample dcWeekExample = new DcWeekExample();
//        DcWeekExample.Criteria criteria = dcWeekExample.createCriteria();
//        criteria.andYearEqualTo(Integer.toString(year));
//        criteria.andYearWeekEqualTo(Integer.toString(week));
//        List<DcWeek> dcWeekList = dcWeekMapper.selectByExample(dcWeekExample);
//        if(dcWeekList.size()>0){
//            nowWeekInfo.setWeek(year+"年" +month+"月第" + dcWeekList.get(0).getMonthWeek() + "期");
//        }else{
//            nowWeekInfo.setWeek(year+"年" +"第" + week + "周");
//        }
//        nowWeekInfo.setStartDate(weekBegin);
//        nowWeekInfo.setEndDate(weekEnd);
//        logger.info("**********************结束:获取当前周信息**************************");
//        return  nowWeekInfo;
//    }
//
//}
